import QtQuick 2.0

Rectangle {

    property int minVal: 1
    property int maxVal: 100
    property string which: ""
    property int hx: 200

    signal sigValue(string which, int v)

    color: "transparent"

    property int angle: 0

    rotation: angle


    Rectangle {
        id: body
        width: 30
        height: hx
        radius: 10
        color: "gray"
        border.width: 2
        anchors.centerIn: parent
    }

    Rectangle {
        id: slider
        width: 45
        height: 30
        radius: 10
        color: "darkgray"
        anchors.horizontalCenter: parent.horizontalCenter
        y: 0

        MouseArea {
            anchors.fill: parent
            drag.target: slider
            drag.axis: Drag.YAxis
            drag.minimumY: 0
            drag.maximumY: hx-20
        }

        onYChanged: {
            emit: sigValue(which, slider.y/(hx-20)*(maxVal-minVal)+minVal)
        }
    }

    Text {
        id: txtSlider
        font.pixelSize: 16
        color: "white"
        text: parseInt(slider.y/(hx-20)*(maxVal-minVal)+minVal) + ""
//        anchors.left: slider.right
//        anchors.leftMargin: 3
//        anchors.top: slider.top
//        anchors.topMargin: 5
        anchors.centerIn: slider
        rotation: -angle
    }


    PropertyAnimation {
        id: pa
        targets: [slider]
        property: "scale"
        from: 1.3
        to: 1.0
        duration: 200
    }

    function setValue(v) {
        slider.y = parseInt(v-minVal)*(hx-20)/(maxVal-minVal)
    }

    function playAni() {
        pa.start()
    }


}

